import os
import tkinter as tk
from tkinter.filedialog import askdirectory
import tkinter.font as tf
from tkinter import ttk


window = tk.Tk()
window.title("重命名工具")
window.geometry("400x150")

font = tf.Font(family = "华文仿宋",size=12)

#f1 = tk.Frame(window,width=150,height=40,bg="black")
#f1.grid(row=10,column=0)
#f1.pack(side = tk.LEFT)
l1 = tk.Label(window,width = 20,text = "自定名称：")
l1.grid(row=0,column=0)


'''
t1 = tk.Text(window,width=17,height=1,font = font)
t1.grid(row=0,column=0)
t1.insert("end","您选择的文件夹是:")

t2 = tk.Text(window,width=50,height=1,font = font)
t2.grid(row=0,column=1)


def ask():
    path_ = askdirectory()
    t2.insert("end",str(path_))

b1 = tk.Button(window,width=10,text="选择文件夹", font = tf.Font(family = "华文仿宋",size=10),command = ask)
b1.grid(row=0,column=2)

'''



def rename():
    path = r'F:\电脑备份\课程\化学必修2\同步强化班'
    count = 1
    filelist = os.listdir(path)
    for files in filelist:
        Olddir = os.path.join(path,files)
        filename1 = os.path.splitext(files)[0]
        filename2 = filename1.split("讲")[0]
        filenamepath = filename1.split("讲")[1]

        Newdir = os.path.join(path,"第"+str(count)+"讲"+filenamepath)
        os.rename(Olddir,Newdir)
        count+=1
    

window.mainloop()

